home *** CD-ROM | disk | FTP | other *** search
- package hhapplet;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Rectangle;
- import java.awt.image.ImageObserver;
-
- public class TabButton extends CanvasButton {
- protected String label;
- protected int x_offset = -1;
- protected int y_offset = -1;
- protected Font active;
- protected Font inactive;
- protected int tab_x;
- protected int tab_y;
- protected int tab_width;
- protected int tab_height;
-
- public void reshape(int var1, int var2, int var3, int var4) {
- super.reshape(var1, var2, var3, var4);
- this.tab_x = var1;
- this.tab_y = var2;
- this.tab_width = var3;
- this.tab_height = var4;
- this.centerText();
- }
-
- public TabButton(String var1) {
- int var2 = WebHelp.GetFontSize();
- this.active = new Font(WebHelp.GetFontName(), 1, var2);
- this.inactive = new Font(WebHelp.GetFontName(), 0, var2);
- ((Component)this).setFont(this.inactive);
- this.label = var1;
- }
-
- public void paint(Graphics var1) {
- var1.setColor(((Component)this).getBackground());
- var1.fillRect(0, 0, ((Component)this).bounds().width, ((Component)this).bounds().height);
- if (super.img != null) {
- var1.drawImage(super.img, 2, 2, (ImageObserver)null);
- } else if (this.label != null) {
- if (this.x_offset == -1 || this.y_offset == -1) {
- this.centerText();
- }
-
- var1.setColor(((Component)this).getForeground());
- var1.setFont(((Component)this).getFont());
- var1.drawString(this.label, this.x_offset, this.y_offset);
- }
-
- if (super.button_push_state) {
- this.paintBorderIn(var1);
- } else {
- this.paintBorderOut(var1);
- }
- }
-
- public void paintBorderOut(Graphics var1) {
- Rectangle var2 = ((Component)this).bounds();
- Color var3 = ((Component)this).getBackground().brighter();
- Color var4 = var3.darker();
- Color var5 = var4.darker();
- Color var6 = var5.darker();
- var1.setColor(var5);
- var1.drawLine(var2.width - 2, 1, var2.width - 2, var2.height - 2);
- var1.setColor(var6);
- var1.drawLine(var2.width - 1, 1, var2.width - 1, var2.height - 2);
- var1.setColor(var4);
- var1.drawLine(1, 1, var2.width - 2, 1);
- var1.drawLine(1, 1, 1, var2.height - 2);
- if (((Component)this).isEnabled()) {
- var1.drawLine(0, var2.height - 1, var2.width, var2.height - 1);
- }
-
- var1.setColor(var3);
- var1.drawLine(1, 0, var2.width - 2, 0);
- var1.drawLine(0, 1, 0, var2.height - 2);
- if (((Component)this).isEnabled()) {
- var1.drawLine(0, var2.height - 2, var2.width, var2.height - 2);
- }
-
- }
-
- public void paintBorderIn(Graphics var1) {
- Rectangle var2 = ((Component)this).bounds();
- Color var3 = ((Component)this).getBackground().brighter();
- Color var4 = var3.darker();
- Color var5 = var4.darker();
- Color var6 = var5.darker();
- var1.setColor(var6);
- var1.drawLine(0, 0, var2.width - 1, 0);
- var1.drawLine(0, 0, 0, var2.height - 1);
- var1.setColor(var5);
- var1.drawLine(1, 1, var2.width - 2, 1);
- var1.drawLine(1, 1, 1, var2.height - 2);
- var1.setColor(var4);
- var1.drawLine(var2.width - 2, 1, var2.width - 2, var2.height - 2);
- var1.setColor(var3);
- var1.drawLine(var2.width - 1, 1, var2.width - 1, var2.height - 1);
- }
-
- public void disable() {
- if (((Component)this).isEnabled()) {
- ((Component)this).setFont(this.active);
- super.reshape(this.tab_x, this.tab_y, this.tab_width, this.tab_height);
- this.centerText();
- ((Component)this).repaint();
- super.disable();
- }
-
- }
-
- public void enable() {
- if (!((Component)this).isEnabled()) {
- ((Component)this).setFont(this.inactive);
- super.reshape(this.tab_x, this.tab_y + 3, this.tab_width, this.tab_height - 3);
- this.centerText();
- ((Component)this).repaint();
- super.enable();
- }
-
- }
-
- public void enable(boolean var1) {
- if (var1) {
- this.enable();
- } else {
- this.disable();
- }
- }
-
- public Dimension preferredSize() {
- try {
- if (super.img != null) {
- return new Dimension(super.img.getWidth(this) + 4, super.img.getHeight(this) + 4);
- } else if (this.label != null) {
- FontMetrics var1 = ((Component)this).getFontMetrics(((Component)this).getFont());
- int var2 = var1.stringWidth(this.label);
- int var3 = var1.getMaxAscent();
- var2 += 4 + 2 * var1.getMaxAdvance();
- var3 += 4 + var1.getMaxDescent();
- return new Dimension(var2, var3);
- } else {
- return new Dimension(20, 20);
- }
- } catch (Exception var4) {
- return new Dimension(20, 20);
- }
- }
-
- protected void centerText() {
- Rectangle var1 = ((Component)this).bounds();
- FontMetrics var2 = ((Component)this).getFontMetrics(((Component)this).getFont());
- int var3 = var2.stringWidth(this.label);
- int var4 = var2.getMaxAscent();
- this.y_offset = var1.height - var4;
- this.y_offset = this.y_offset / 2 + var4;
- this.x_offset = var1.width - var3;
- this.x_offset /= 2;
- }
- }
-